<?php

namespace T4\VIEW;

class TwigAdapter {

	public function __construct() {
		
	}

	public function render($view, $template) {

		$paths = $view->getPaths();
		array_unshift($paths, dirname($template));

		$loader = new \Twig_Loader_Filesystem($paths);
		$params = array();

		$config = \T4\Config::getInstance(\ROOT_PATH . '/config/common.yaml');
		if ($config->cache->templates == 'On') {
			$params['cache'] = \ROOT_PATH . '/cache/templates';
		}

		$twig = new \Twig_Environment(
						$loader,
						$params
		);

		$template = $twig->loadTemplate(basename($template));

		return $template->render($view->getData());
		
	}

}